/**
 *  *2010-7-26 下午04:41:27  add 
 */
package com.base.myproject.client.HR.Salary;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.base.myproject.client.HR.bcode.BcodeSelectDialog;
import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.busi.BO.TreeNodeModelData;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncExeSql;
import com.base.myproject.client.tools.CommandSyncMakeCode;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dev.protobuf.Message;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;

/**
 * 计算花红
 * 
 * @author Administrator 2010-7-26 javazgw@gmail.com
 * update cxghiu410@gmail.com
 * 
 * 添加新的花红时，花红的日期一定要包含发放工资的日期
 */
public class Salary_Bonus extends BaseJDBCPanel {
	BcodeSelectDialog<TreeNodeModelData> bsd_add;

	NumberField percentage = new NumberField();  //花红比例

	Button addbutton = new Button("添加");

	Button query = new Button("查询");

	String salaryno = null;  //记录要进行添加的花红编号，可能是从服务器接收的，也可能是还没发完的花红编号

	boolean insert = true; // 记录添加花红为新添加的还是接着添加的，新的为false,接着添加的为true

	int max = 1;  //保存花红发放的次数，新的为1，接着添加的话就在已经添加的次数上加1

	// 页面上的6个日期字段
	DateField datef = new DateField();
	DateField dateField9 = new DateField();
	DateField dateField13 = new DateField();
	DateField dateStart = new DateField();
	DateField dateEnd = new DateField();
	DateField dateField6 = new DateField();

	BaseStore<BaseModelData> boxStore;  //保存还没添加完的的花红编号
	BaseComboBoxForm<BaseModelData> bc16;  //花红编号的ComboBox

	public Salary_Bonus() {
		init();
	}

	public void init() {
		bc16 = new BaseComboBoxForm<BaseModelData>(getBoxStore());
		bc16.addListener(Events.Change, getListener());  //Change事件，但是现在还不能实现一选择就让From的数据变化
		initWedgitx();
		registerMainStore(store);
		registerStore(store);
		registerStore(boxStore);
	}

	void initWedgitx() {
		VerticalPanel vpanel = new VerticalPanel();
		vpanel.setSpacing(2);
		vpanel.add(seach_Form());
		vpanel.add(add_Form());
		vpanel.add(createGrid());
		add(vpanel);

	}

	FormPanel form1 = null;

	BaseComboBoxForm<BaseModelData> bName;
	BaseComboBoxForm<BaseModelData> salaryNo;
	
	FormPanel seach_Form() {
		FormPanel form = new FormPanel();
		TableLayout tl = new TableLayout(8);
		form.setWidth(990);
		form.setBorders(false);
		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		form.setLayout(tl);
		form.setHeaderVisible(false);

		form.add(new Label("查询日期:"), td);
		form.add(datef, td);
		form.add(new Label("人员："), td);
		bName = new BaseComboBoxForm<BaseModelData>(
				"bcode","bname","bcode_job"," where employstatus='在职'",true);
		form.add(bName, td);
		form.add(new Label("花红编号："), td);
		salaryNo = new BaseComboBoxForm<BaseModelData>(
				"salaryno", "salaryno", "hr_salary_bonus", "group by salaryno", true);
		form.add(salaryNo, td);
		query.addListener(Events.Select, getListener());
		form.add(query, td);
		return form;
	}
	
	private List<String> getAllBcodelist(TreeNodeModelData data) {
		List<String> bcodeList = new ArrayList<String>();
		if (data.getChildCount() != 0) {
			for (ModelData node : data.getChildren()) {
				bcodeList.addAll(getAllBcodelist((TreeNodeModelData)node));
			}
		} else {
			if (data.get("bcode") != null) {
				bcodeList.add(data.get("bcode").toString());
			}
		}
		return bcodeList;
	}

	FormPanel form2 = null;
	List<String> bcodeList;  //用于保存Dialog选中的所有员工的bcode，用于添加新的花红

	FormPanel add_Form() {
		FormPanel form = new FormPanel();
		TableLayout tl = new TableLayout(6);
		form.setWidth(990);
		form.setBorders(false);
		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		form.setLayout(tl);
		form.setHeaderVisible(false);

		bsd_add = new BcodeSelectDialog<TreeNodeModelData>() {
			public void doposted(List<TreeNodeModelData> modeldatalist) {
				if (modeldatalist.size() > 0) {
					bcodeList = new ArrayList<String>();
					String bcode_str = "";
					for (int i = 0; i < modeldatalist.size(); i++) {
						bcode_str = bcode_str + ";"
								+ modeldatalist.get(i).get("bname");
						bcodeList.addAll(getAllBcodelist(modeldatalist.get(i)));
					}
					bcode_str = bcode_str.substring(1, bcode_str.length());
					this.setEmptyText(bcode_str);  //一旦Dialog选择了员工，就让bsd_add显示所有选中员工的名字
					insert = false;
				}

				//从服务器上得到新的花红编号，保存在salaryno中。
				CommandSyncContainer list = new CommandSyncContainer();
				CommandSyncMakeCode csmc = new CommandSyncMakeCode();

				csmc.setBeginstr("c");
				csmc.setColumnname("salaryno");
				csmc.setTablename("hr_salary_bonus");
				list.add(csmc);

				final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService.SendCommandSync(list,
						new AsyncCallback<CommandSyncReturnObject>() {
							public void onFailure(Throwable caught) {
								Window.alert("网络连接不稳定，请稍后重试！");
							}

							public void onSuccess(CommandSyncReturnObject cyro) {

								if (cyro.isB()) {
									salaryno = cyro.getRetrunstr();
								} else {
									Window.alert("分配内码时出错。");
								}
							}
						});
				bc16.setEnabled(false);
				percentage.setMaxValue(1);
				percentage.setValue(1);
				max = 1;
				
				//得到编号后，让花红编号的列表框为不可用，并设置比例默认值为1，max也设置为1，表示第一次添加
				//该编号的花红。
			}
		};
		bsd_add.setNeesreselect(false);
		bsd_add.setEmptyText("未选择数据");
		bsd_add.setExpanded();
		form.add(new Label("选择人员:"), td);
		form.add(bsd_add, td);
		form.add(new Label("花红编号:"), td);
		query.addListener(Events.Select, getListener());
		form.add(bc16, td);
		form.add(new Label("发放比例:"), td);
		percentage.setValue(1);
		percentage.setMaxValue(1);
		percentage.addListener(Events.Change, getListener());
		form.add(percentage, td);
		form.add(new Label("花红开始日期:"), td);
		dateStart.getPropertyEditor().setFormat(
				DateTimeFormat.getFormat("yyyy-MM-dd"));
		form.add(dateStart, td);
		form.add(new Label("花红截止日期:"), td);
		dateEnd.getPropertyEditor().setFormat(
				DateTimeFormat.getFormat("yyyy-MM-dd"));
		form.add(dateEnd, td);

		form.add(addbutton, td);
		addbutton.addListener(Events.Select, getListener());
		return form;
	}

	/***/

	BaseStore<BaseModelData> getBoxStore() {
		if (boxStore == null) {
			createBoxStore();
		}
		return boxStore;
	}

	/**
	 * @return bc16的store
	 * 这个store用了一个sql来得到所有还没发放完的花红编号
	 */
	BaseStore<BaseModelData> createBoxStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("name");
		type.addField("percentage");
		type.addField("code");
		type.addField("bonusstartdate");
		type.getField("bonusstartdate").setType(Date.class);
		type.addField("bonusenddate");
		type.getField("bonusenddate").setType(Date.class);

		StoreInfo info = new StoreInfo();
		info.setTablename("hr_salary_bonus");
		info
				.setSql("select name,sum(percentage) as percentage,max(code) as code,bonusstartdate,"
						+ " bonusenddate from (select salaryno as name,max(ordernum) as code,percentage, "
						+ "bonusstartdate, bonusenddate from hr_salary_bonus group by salaryno,bonusstartdate, "
						+ "bonusenddate,percentage,bonusdate) as a group by name,bonusstartdate, bonusenddate having sum(percentage)<1");
		
		boxStore = new BaseStore<BaseModelData>(type, info);
		return boxStore;
	}

	BaseStore<BusiObject> store = null;

	BaseStore<BusiObject> getStore() {
		if (store == null) {
			createStore();
		}
		return store;
	}

	/**
	 * @return grid要用于的store数据
	 * 得到当前月的所有发放花红的记录
	 */
	BaseStore<BusiObject> createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("no_");
		type.getField("no_").setType(String.class);
		type.addField("amount");
		type.getField("amount").setType(Double.class);
		type.addField("multiple");
		type.getField("multiple").setType(Double.class);
		type.addField("salaryno");
		type.getField("salaryno").setType(String.class);
		type.addField("percentage");
		type.getField("percentage").setType(Double.class);
		type.addField("bonusdate");
		type.getField("bonusdate").setType(Date.class);

		type.addField("ordernum");
		type.getField("ordernum").setType(Integer.class);
		type.addField("bonusstartdate");
		type.getField("bonusstartdate").setType(Date.class);

		type.addField("bonusenddate");
		type.getField("bonusenddate").setType(Date.class);

		StoreInfo info = new StoreInfo();
		info.setTablename("hr_salary_bonus");
		info.setKeyname(new String[] { "icode" });
		info.setForcenolimit("true");
		info
				.setSql("select * from hr_salary_bonus where datediff(month,getdate(),bonusdate )=0 order by bonusdate desc ");

		store = new BaseStore<BusiObject>(type, info);
		return store;
	}

	BaseGridPanel grid = null;

	BaseGridPanel createGrid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C2 = new ColumnConfig("bcode", "人员", 80);

		BaseComboBoxForm<BaseModelData> bsb2 = new BaseComboBoxForm<BaseModelData>(
				"bcode","bname","bcode_job"," where employstatus='在职'",true);
		C2.setRenderer(bsb2);
		columns.add(C2);
		// ColumnConfig C3 = new ColumnConfig("no_", "no_", 80);
		// columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("amount", "金额", 80);
		NumberField nfc4 = new NumberField();
		C4.setEditor(new CellEditor(nfc4));
		columns.add(C4);

		ColumnConfig C5 = new ColumnConfig("multiple", "倍数", 80);
		C5.setWidth(100);
		columns.add(C5);
		ColumnConfig C6 = new ColumnConfig("salaryno", "发薪编号", 80);
		columns.add(C6);
		ColumnConfig C7 = new ColumnConfig("percentage", "花红发放比例", 120);

		columns.add(C7);

		ColumnConfig C9 = new ColumnConfig("ordernum", "花红发放次数", 120);

		columns.add(C9);

		ColumnConfig C12 = new ColumnConfig("bonusstartdate", "花红开始日期", 80);
		C12.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C12);

		ColumnConfig C13 = new ColumnConfig("bonusenddate", "花红截止日期", 80);
		C13.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C13);

		ColumnConfig C8 = new ColumnConfig("bonusdate", "添加日期", 80);

		C8.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C8);

		ColumnModel cm = new ColumnModel(columns) {
			public String getColumnStyle(int colIndex) {
				if (colIndex == 3) {

					return " background-color: #FFFF99 ;";
				}

				return configs.get(colIndex).getStyle();

			}
		};
		grid = new BaseGridPanel(getStore(), cm, true, true) {

			protected void addnewrecord() {
				MessageBox.alert("提示", "禁止使用！如果需要添加，请使用界面上方的添加按钮", null);
			}

			protected void delrecord() {
				int idx = 0;
				for (int j = 0; j < bg.getSelectionModel().getSelectedItems()
						.size(); j++) {
					bg.getStore().remove(
							(ModelData) bg.getSelectionModel()
									.getSelectedItems().get(j));
					idx = idx == 0 ? 0 : idx - 1;
				}
				bg.getSelectionModel().select(idx, false);
				bg.getStore().trySave();
			}
		};
		grid.getLC2().remove(grid.getAddbutton());
		grid.getLC2().remove(grid.getCanceldelbutton());
		cbs.setSelectionMode(SelectionMode.MULTI);
		grid.getBg().setSelectionModel(cbs);
		grid.getBg().setWidth(990);
		grid.getBg().setHeight(320);
		return grid;
	}

	int sync = 0;
	Listener<BaseEvent> defaultlistener;

	Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}

		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
				try {
					if (sync == 1) {
						if (be.getType() == Events.Select) {

							if (be.getSource().equals(query)) {
								if(datef.getValue() == null && bName.getValue() == null && salaryNo.getValue() == null) {
									MessageBox.alert("错误", "请选择查询条件，可选一个也可多选", null);
									return;
								}
								String sql = "select * from hr_salary_bonus  where 1=1";
								String where = "";
								if (datef.getValue() != null) {
									DateTimeFormat dtf = DateTimeFormat
											.getFormat("yyyy-MM-dd");
									where = where + " and datediff(month,'" + dtf.format(datef.getValue())
											+ "',bonusdate )=0";
								}
								if (bName.getValue() != null) {
									where = where + " and bcode = '" + bName.getValue().get("code") + "'";
								}
								if (salaryNo.getValue() != null) {
									where = where + " and salaryno = '" + salaryNo.getValue().get("name") + "'";
								}
								sql = sql + where;
								String sqlbefo = store.getStoreinfo()
								.getSql();
								store.getStoreinfo().setSql(sql);
								store.reload();
								store.getStoreinfo().setSql(sqlbefo);
							}
							if (be.getSource().equals(addbutton)) {
								/*
								 * 用了4个if做数据完整性的控制，让用户填写完整的发红发放数据
								 */
								if (bc16.getValue() == null
										&& bsd_add.getEmptyText().equals("未选择数据")) {
									MessageBox.alert("错误", "请选择花红编号或选择员工", null);
									return;
								}
								if (percentage.getValue() == null) {
									MessageBox.alert("错误", "请填写花红比例", null);
									return;
								}
								
								if (dateStart.getValue() == null && dateEnd.getValue() ==null) {
									MessageBox.alert("错误", "请选择开始日期和结束日期", null);
									return;
								}
								
								if (dateStart.getValue().getTime() >= dateEnd.getValue().getTime()) {
									MessageBox.alert("错误", "开始日期不能大于或等于结束日期", null);
									return;
								}

								/*
								 * 下面2个语句用于清空Dialog选中的数据，并设置bsd_add显示的字符
								 */
								bsd_add.deselectall();
								bsd_add.setEmptyText("未选择数据");

								addBonus();  //调用添加方法
							}
						} else if (be.getType() == Events.Change) {
							if (be.getSource().equals(percentage)) {
								/*
								 * 控制输入的值不能大于可以再发放的花红的比例值，如果超过了就返回最大的比例值
								 */
								if(percentage.getValue() != null) {
									if (percentage.getValue().doubleValue() > percentage
											.getMaxValue().doubleValue()) {
										percentage.setValue(percentage
												.getMaxValue());
										MessageBox.alert("错误",
												"你填写的数值大于可发放的花红比例，最大值为"
														+ percentage.getMaxValue()
																.doubleValue(),
												null);
										return;
									}
								}
							}
							if (be.getSource().equals(bc16)) {
								/*
								 * 控制如果bc16的值为空或选中了不存在的值的话，提示用户重新选择。
								 * 如果不存在以上两种情况的话，就根据选中的值来更改form中的percentage,dateStart
								 * 和dateEnd的值，并让max值自动加1；
								 */
								if (bc16.getValue() == null && bc16.getValue().get("name") == null) {
									MessageBox.alert("错误", "请选择正确的编号", null);
								} else {
									double value = ((double) (int) ((1.00 - Double
											.parseDouble(bc16.getValue().get(
													"percentage").toString())) * 100 + 0.5)) / 100;
									percentage.setMaxValue(value);
									percentage.setValue(value);
									bsd_add.setEnabled(false);
									salaryno = (String) bc16.getValue().get(
											"name");
									dateStart.setValue((Date) bc16.getValue()
											.get("bonusstartdate"));
									dateEnd.setValue((Date) bc16.getValue()
											.get("bonusenddate"));
									dateStart.setReadOnly(true);
									dateEnd.setReadOnly(true);
									max = Integer.parseInt((String) bc16
											.getValue().get("code")) + 1;
								}
							}

						} else if (be.getType() == Events.KeyPress) {
							GWT.log("-------");
						} else if (be.getType() == Events.KeyUp) {

							if (be.getSource().equals(dateField6))
								if (be instanceof ComponentEvent) {
									if (((ComponentEvent) be).getKeyCode() == 13
											|| ((ComponentEvent) be)
													.getKeyCode() == 10) // 回车
									{
										getStore().addX();
									}
								}
						}
					}
				} finally {
					sync--;
				}
			}

		};
		return defaultlistener;
	}

	/**
	 * @return 暂时还没作用的
	 * 做添加花红操作，根据新添加的和继续添加的两种不同的类型生成不同的sql语句，并传给sendSql方法。
	 */
	private boolean addBonus() {
		String sql = "";
		DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");
		String end = dtf.format(dateEnd.getValue());
		String start = dtf.format(dateStart.getValue());
		if (insert) {
			String sqlStart = "insert into hr_salary_bonus(bcode,no_,amount,multiple,bonusdate,salaryno," +
					"percentage,ordernum,bonusstartdate,bonusenddate) select distinct bcode,'A77'," +
					"amount,multiple,getdate(),salaryno,";
			String insertSql = "";
			String sqlEnd = ",bonusstartdate,bonusenddate from hr_salary_bonus where salaryno = '" + salaryno + "'";
			insertSql = insertSql + percentage.getValue() + "," + max;
			sql = sqlStart + insertSql + sqlEnd;
		} else {
			String insertSql = "";
			String sqlStart = "insert into hr_salary_bonus(bcode,no_,amount,multiple,bonusdate,salaryno,"
					+ "percentage,ordernum,bonusstartdate,bonusenddate) select a.bcode,'A77',a.basesalary*"
					+ "c.multiple,c.multiple,getdate()";
			String sqlEnd = " from (select a.bcode,sum(a.amount)/12 as basesalary from hr_salary a, hr_salary_main_c b "
					+ ",s_range_view c where a.upcode=b.code and b.start_time>='" + start
					+ "' and case when isnull(b.end_time,'')='' then '" + end + "' else b.end_time end <='"
					+ end + "' and a.allowanceno_ in (select code from hr_salary_item where ifbonus=1) "
					+ "and a.bcode=c.bcode and c.sheetcode='Salary_Bonus_ploy' and c.upcode=(select "
					+ "icode from hr_salary_bonus_ploy_m where ploystartdate<='" 
					+ start + "' and case when isnull(ployenddate,'')='' then '" + end 
					+ "' else ployenddate end>='" + start + "') group by a.bcode) as a left join (select "
					+ "Work_experience,bcode from bcode_job) as b on a.bcode=b.bcode left join "
					+ "(select multiple,entryyearstart,entryyearend from hr_salary_bonus_ploy a,"
					+ "hr_salary_bonus_ploy_m b where '" + start + "' between b.ploystartdate and "
					+ " case when isnull(b.ployenddate,'')='' then '"
					+ end + "' else b.ployenddate end and '" 
					+ end + "' between b.ploystartdate and case when isnull(b.ployenddate,'')='' then '" 
					+ end + "' else b.ployenddate end and a.codename = b.codename) as c on "
					+ "b.Work_experience >= c.entryyearstart and  b.Work_experience < c.entryyearend where a.bcode in ";
			String whereSql = "('";
			for (String bcode : bcodeList) {
				whereSql = whereSql + bcode + "','";
			}
			whereSql = whereSql.substring(0, whereSql.length() - 2) + ")";
			insertSql = ",'" + salaryno + "'," + percentage.getValue() + "," + max
					+ ",'" + start + "','"
					+ end + "'";
			sql = sqlStart + insertSql + sqlEnd + whereSql;
		}
		sendSql(sql);
		return true;
	}

	/**
	 * @param sql 用于执行的sql语句
	 * 向服务器发送添加花红的sql语句，执行添加操作，并在添加成功后将form的组件状态设置为最初的状态。并刷新两个store
	 */
	private void sendSql(String sql) {
		CommandSyncsql csql = new CommandSyncsql();// 执行sql命令
		csql.getV().add(sql);
		if (csql.getV().size() <= 0) {
			//return false;    以后做处理
		} else {
			CommandSyncContainer list = new CommandSyncContainer();// 可以添加的命令
			list.add(csql);

			GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
			greetingService.SendCommandSync(list,
					new AsyncCallback<CommandSyncReturnObject>() {
						@Override
						public void onFailure(Throwable caught) {
							MessageBox.alert("错误", "网络连接失败", null);
						}

						@Override
						public void onSuccess(CommandSyncReturnObject result) {
							if (result.isB()) {
								Info.display("提示信息", "添加成功");
								bsd_add.setEnabled(true);
								bc16.setEnabled(true);
								dateStart.setReadOnly(false);
								dateEnd.setReadOnly(false);
								insert = true;
								bc16.setValue(null);  //这里还有点问题，不知道怎么设置bc16，又让bc16不提示null的，以后再改
								getStore().reload();
								boxStore.reload();
							} else {
								MessageBox.alert("错误", "错误，错误代码"
										+ result.getMessage(), null);

							}
						}
					});
		}
	}
}
